/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import javax.swing.JOptionPane;
import src.Core;
import src.LinkedLists;

/**
 *
 * @author Strauzen
 */
public class VentanaFichero extends javax.swing.JFrame {

    int padre;
    Ventana1 v1;
    Ventana3 v3;
    VentanaCargo vc;
    VentanaColectivo vco;
    VentanaAcontecimiento vac;
    
        private boolean comprobar(){
        String mensaje = "";
        boolean resultado = false;
        
        if (this.jTextField_vfNombre.getText().equals(""))
            mensaje += "Por favor rellene el campo de nombre\n\n";
        if (!parsearURI(this.jTextField_vfUri.getText()))
            mensaje += "Por favor rellene el campo del URI de las palabras clave con una dirección valida\n e.j. C:.ejemplo\n"
                    + "Los . diferencian carpetas\n\n";
        
        if ("".equals(mensaje))
            resultado =true;
        else
            JOptionPane.showMessageDialog(null, mensaje);
        
        return resultado;
    }
        
    private boolean parsearURI(String uri){
        boolean resultado = false;
        
        if(!uri.equals("") && (uri.length() > 2))
            if(uri.charAt(1) == ':' && uri.charAt(2) == '.')
                resultado = true;
        
        return resultado;
    }
    
    /**
     * Creates new form VentanaFichero
     */
    public VentanaFichero(Ventana1 v1, Ventana3 v3, VentanaCargo vc) {
        this.v1 = v1;
        this.v3 = v3;
        this.vc = vc;
        initComponents();
    }

    public VentanaFichero(Ventana1 v1, Ventana3 v3, VentanaColectivo vco) {
        this.v1 = v1;
        this.v3 = v3;
        this.vco = vco;
        initComponents();
    }

    public VentanaFichero(Ventana1 v1, Ventana3 v3, VentanaAcontecimiento vac) {
        this.v1 = v1;
        this.v3 = v3;
        this.vac = vac;
        initComponents();
    }
    
    public void setPadre(int padre){
        this.padre = padre;
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel_vfNombre = new javax.swing.JLabel();
        jTextField_vfNombre = new javax.swing.JTextField();
        jLabel_vfUri = new javax.swing.JLabel();
        jTextField_vfUri = new javax.swing.JTextField();
        jComboBox_vfFormato = new javax.swing.JComboBox();
        jButton_vfTerminar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Añadir Fichero");
        setName("Añadir Fichero"); // NOI18N

        jPanel1.setToolTipText("");

        jLabel_vfNombre.setText("Nombre");

        jLabel_vfUri.setText("URI");

        jComboBox_vfFormato.setModel(new javax.swing.DefaultComboBoxModel(new String[] { ".txt", ".pdf", ".word" }));

        jButton_vfTerminar.setText("Terminar");
        jButton_vfTerminar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_vfTerminarMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel_vfNombre)
                    .addComponent(jLabel_vfUri))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextField_vfNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 334, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jTextField_vfUri, javax.swing.GroupLayout.DEFAULT_SIZE, 265, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBox_vfFormato, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(160, Short.MAX_VALUE)
                .addComponent(jButton_vfTerminar)
                .addGap(146, 146, 146))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel_vfNombre)
                    .addComponent(jTextField_vfNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel_vfUri)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextField_vfUri, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jComboBox_vfFormato, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton_vfTerminar)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton_vfTerminarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_vfTerminarMouseClicked
        // TODO add your handling code here:
        if(comprobar()){
            int f = Core.CrearFichero(jTextField_vfNombre.getText(), jTextField_vfUri.getText(), jComboBox_vfFormato.getToolTipText());
            switch(padre){
                case 1:
                    vc.setVisible(true);
                    this.setVisible(false);  
                    LinkedLists.anadeFicheroParaCargos(f);
                    this.dispose();
                    break;
                case 2:
                    vco.setVisible(true);
                    this.setVisible(false);
                    LinkedLists.anadeFicheroParaColectivos(f);
                    this.dispose();
                    break;
                case 3:
                    vac.setVisible(true);
                    this.setVisible(false);
                    LinkedLists.anadeFicheroParaAcontecimientos(f);
                    this.dispose();
                    break;
            }
        }
    }//GEN-LAST:event_jButton_vfTerminarMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton_vfTerminar;
    private javax.swing.JComboBox jComboBox_vfFormato;
    private javax.swing.JLabel jLabel_vfNombre;
    private javax.swing.JLabel jLabel_vfUri;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField jTextField_vfNombre;
    private javax.swing.JTextField jTextField_vfUri;
    // End of variables declaration//GEN-END:variables
}
